package com.zxj.system.controller.question;


import com.zxj.common.core.controller.BaseController;
import com.zxj.common.core.domain.R;
import com.zxj.common.core.domain.vo.PageVO;
import com.zxj.system.domain.question.dto.QuestionAddDTO;
import com.zxj.system.domain.question.dto.QuestionPageQueryDTO;
import com.zxj.system.domain.question.dto.QuestionUpdateDTO;
import com.zxj.system.domain.question.vo.QuestionDetailVO;
import com.zxj.system.domain.question.vo.QuestionVO;
import com.zxj.system.service.question.IQuestionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 问题控制器
 * </p>
 *
 * @author zxj2022
 * @date 2024/12/26
 */
@RestController
@RequestMapping("/question")
@Tag(name = "问题管理接口", description = "问题管理相关接口")
@Slf4j
@RequiredArgsConstructor
public class QuestionController extends BaseController {
    private final IQuestionService questionService;

    @GetMapping("/page/list")
    @Operation(summary = "获取问题列表", description = "分页查询问题列表")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<PageVO<QuestionVO>> pageQuery(QuestionPageQueryDTO questionPageQueryDTO) {
        log.info("接收到分页获取问题信息请求, 请求参数：{}", questionPageQueryDTO);
        return R.ok(questionService.pageQuery(questionPageQueryDTO));
    }


    /**
     * 添加问题
     * @param questionAddDTO
     * @return
     * @see QuestionAddDTO
     */
    @PostMapping
    @Operation(summary = "添加问题", description = "添加问题")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<Void> add(@RequestBody QuestionAddDTO questionAddDTO) {
        log.info("接收到添加问题请求, 请求参数：{}", questionAddDTO);
        return toR(questionService.add(questionAddDTO));
    }


    @GetMapping("/{questionId}")
    @Operation(summary = "获取问题详情", description = "依据题目ID获取问题详情")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<QuestionDetailVO> detail(@PathVariable Long questionId) {
        log.info("接收到获取问题详情请求, 请求参数：{}", questionId);
        return R.ok(questionService.detail(questionId));
    }

    @PutMapping
    @Operation(summary = "修改问题", description = "修改问题")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<Void> updateQuestion(@RequestBody QuestionUpdateDTO questionUpdateDTO) {
        log.info("接收到修改问题请求, 请求参数：{}", questionUpdateDTO);
        return toR(questionService.updateQuestion(questionUpdateDTO));
    }

    @DeleteMapping("/{questionId}")
    @Operation(summary = "删除问题", description = "依据题目ID删除问题")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<Void> delete(@PathVariable Long questionId) {
        log.info("接收到删除问题请求, 请求参数：{}", questionId);
        return toR(questionService.delete(questionId));
    }
}
